<script setup lang="ts">
import { ref, reactive, h } from "vue";
import { getListApi } from "/@/api/mes/finishe-product";
import { useModal } from '/@/hooks/useModal'
import { useConfirm } from '/@/hooks/useMessage'
import { dataFormatter } from '/@/utils/data'


// 表格配置
const tableRef = ref<YTableInstance>();
const tableProps = reactive<YTableProps>({
  height: "auto",
  columns: [
    { field: "workOrderCode", label: "工单编号", width: 150, filter: true },
    { field: "productName", label: "产品名称", width: 100, filter: true },
    { field: "productCode", label: "产品编号", width: 100, filter: true },
    { field: "workOrderQuantity", label: "工单数", width: 100 },
    { field: "quantity", label: "成品数", width: 100 },
    { field: "defectsQuantity", label: "次品数", width: 100 }

  ],
  remoteConfig: {
    api: getListApi,
    immediate: true
  },
  operas: [
    {
      title: '入库',
      type: 'primary',
      onClick: async () => {
        const selects = await tableRef.value.getCheckRecords(true);
        viewModal.open({ contentProps: { ids: selects.map(s => s.id).join() } })
      }
    },
  ]
});

// 编辑窗口
const isChange = ref(false)
const viewModal = useModal({
  title: '成品入库',
  width: 1000,
  height: 600,
  content: () => import('./view.vue'),
  contentOn: {
    onChange: () => {
      isChange.value = true
    }
  }
});

viewModal.on('open', () => {
  isChange.value = false
})
viewModal.on('close', () => {
  if (isChange.value) {
    tableRef.value.loadData()
  }
})

</script>
<template>
  <IndexLayout>
    <YTable v-bind="tableProps" ref="tableRef"></YTable>
  </IndexLayout>
</template>